﻿class odal.OMSNode {
	private var m_id;
	private var m_name;
	private var m_modifyingDate;
	private var m_creatingDate;
	private var m_creater;
	private var m_modifier;
	private var m_state = 0;

	public function del():Boolean {
		var bRet:Boolean = false;
		if ( this.m_state != 1 ){
			this.m_state = 3;
			bRet = true;
		}//if
		//echo "(node.delete) this.m_state:" . this.m_state . "<br>";
		return bRet;
	}//del

	public function update( name ):Boolean {
		var bRet:Boolean = false;
		if ( ( this.m_state == 0 ) || ( this.m_state == 1 ) ){
			//echo "[node.update] this.getId(): " . this.getId() . " - this.getName(): " . this.getName() . "<br>";
			//echo "[node.update] this.m_state: *" . this.m_state. "*<br>";
			this.m_name = name;
			bRet = true;
		}//if
		this.setStateAfterUpdate();
		//echo "[node.update] this.m_state: *" . this.m_state. "*<br>";
		//echo "[node.update] bRet: *" . bRet . "*<br>";
		return bRet;
	}//update

	public function setStateAfterUpdate(){
		if ( this.m_state() == 0 ){
			this.m_state = 2;
		}//if
	}//_pck_setStateAfterUpdate

	public function get Id():String {
		return this.m_id;
	}//getId

	public function get Name():String {
		return this.m_name;
	}//getName

	public function get ModifyingDate():String {
		return this.m_modifyingDate;
	}//getModifyingDate

		public function get CreatingDate():String {
		return this.m_creatingDate;
	}//getCreatingDate

	public function get Creater():String {
		return this.m_creater;
	}//getCreater

	public function get Modifier():String {
		return this.m_modifier;
	}//getModifier
	
	public function get State():Number {
		return this.m_state;
	}//_pck_getState

	public function set Id( id ):Void {
		this.m_id = id;
	}//setId

	public function set State( state ):Void {
		this.m_state = state;
	}//setState

	public function getObjectFromCollectionById( id:String, objColl:Object ):Object {
		//trace( '[OMSNode.getObjectFromCollectionById]' );
		return objColl[ id ];
	}//getObjectFromCollectionById

	public function getObjectFromCollectionByName( name:String, objColl:Object ){
		var retobj:Object = null;
		for ( var i:String in objColl ) { 
			if ( objColl[ i ].Name == name ){
				retobj = objColl[ i ];
				break; 
			}//if  
		}//foreach
		return retobj;
	}//getObjectFromCollectionByName
	
	public function toString():String {
		var ret:String = '';
		for ( var member:String in this ) {
			ret += member + ': ' + this[ member ] + '\n';
		}//for
		return ret;
	}//toString

}//odal.OMSNode 